package com.electronicmallapiidea.controller;

import com.electronicmallapiidea.common.Result;
import com.electronicmallapiidea.entity.LoginForm;
import com.electronicmallapiidea.entity.User;
import com.electronicmallapiidea.service.Impl.UserServiceImpl;
import com.electronicmallapiidea.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@Api("用户信息 ")
//@Configuration
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @ApiOperation("登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginForm loginForm){
        return Result.success(userService.login(loginForm));
    }


    @ApiOperation("注册")
    @PostMapping("/register")
    public Result register(@RequestBody LoginForm loginForm){
        return Result.success(userService.register(loginForm));
    }

    @ApiOperation("个人信息")
    @GetMapping("/userinfo/{username}")
    public Result getUserInfoByName(@PathVariable String username)
    {
        User user = userService.getOne(username);
        return Result.success(user);
    }


}
